<template>
	<view>
		<view class="header" :class="scroll == true ? 'scrollStyle' : ''">
			<view class="logo">
				<image src="../../static/logo.png" mode="widthFix"></image>
			</view>
			<view class="text">
				<view class="t02">{{subAddress}}</view>
			</view>
			<view class="copy" @click="maskChange(true)">{{Lang.lang('share')}}</view>
			<!-- <view class="bsc_box">
				<picker @change="choiceBsc" :value="bscIndex" :range="bscData" :range-key="'name'">
					<view class="bsc_auto">
						<view class="bsci">
							<image src="../../static/logo02.png" mode="widthFix"></image>
						</view>
						<view class="bsc">{{bscText}}</view>
					</view>
				</picker>
			</view> -->
			<view class="lang">
				<picker @change="choiceLang" :value="langIndex" :range="Lang.lang('langData')" :range-key="'name'">
					<image src="../../static/lang.png" mode="widthFix"></image>
				</picker>
			</view>
			<view class="more" @tap="autoListPage">
				<image src="../../static/more.png" mode="widthFix"></image>
			</view>
			<!-- <view class="signin" @tap="autoSignin" v-if="!login">登錄</view>
			<view class="signin02" v-if="login">
				<image src="../../static/login.png" mode="widthFix"></image>
			</view> -->
		</view>
		
		<view class="nav_pupu" v-if="pupu">
			<view class="nav_box" :class="pupu == false ? 'nav_index' : ''">
				<view class="close iconfont" @tap="autoListPage">&#xe608;</view>
				<view class="nav_list">
					<block v-for="(item, index) in navlist" :key="index">
						<view class="list" :data-url="item.url" @click="gotopage">
							<view class="icon">
								<image :src="item.img" mode="widthFix"></image>
							</view>
							<view class="name">{{ item.name }}</view>
							<view class="arrow iconfont">&#xe601;</view>
						</view>
					</block>
				</view>
			</view>
		</view>
		
		<view class="mask" v-if="mask">
			<view class="m_box">
				<view class="m_item">
					<view class="iconfont close" @click="maskChange(false)">&#xe608;</view>
					<view class="m_tit">{{Lang.lang('share_friends')}}</view>
					<view class="m_qr_itme">
						<!-- <image class="qr_code" src="../../static/index/qr_img.png"></image> -->
						<uv-qrcode ref="qrcode" :options="options2" :value="shareUrl"></uv-qrcode>
					</view>
					<view class="m_t1">{{Lang.lang('share_connection')}}</view>
					<view class="m_t2">{{shareUrl}}</view>
					<view class="btn" @click="copyText" :data-txt="shareUrl">{{Lang.lang('copy_connection_registration')}}</view>
				</view>
			</view>
		</view>
		
		<view class="pupu_box" v-if="login_win">
			<view class="pupu_show" @tap.stop="">
				<view class="title">{{Lang.lang('loginTile')}}</view>
				<view class="text">{{Lang.lang('loginText')}}</view>
				<view class="input"><input type="text" v-model="myAddress"  /></view>
				<view class="text">{{Lang.lang('loginText02')}}</view>
				<view class="input"><input type="text" v-model="inviteId"  /></view>
				<view class="menu_box">
					<!-- <view class="menu" @tap="autoSignin">取消</view> -->
					<view class="menu001" @click="register()">{{Lang.lang('login')}}</view>
				</view>
			</view>
		</view>
		<view class="clear_box"></view>

		<view class="content_box">


			<view class="main02">
				<view class="kuai01 se01">
					<view class="zuob">
						<!-- <view class="balance">余額(USDT)</view>
						<view class="money">2689.56</view> -->
						<view class="content">
							<view class="piece">
								<view class="biao">
									<!-- <view class="line"></view> -->
									<view class="text">{{Lang.lang('balance')}}(LSD)</view>
								</view>
								<view class="qian">{{lsdBalance}}</view>
							</view>
							<view class="piece">
								<view class="biao">
									<!-- <view class="line"></view> -->
									<view class="text">{{Lang.lang('balance')}}({{Lang.lang('rune')}})</view>
								</view>
								<view class="qian">{{fuwenBalance}}</view>
							</view>
						</view>
					</view>
					<view class="youb">
						<image src="../../static/my/wallet2.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="a-center">
					<view class="lump" data-url="/pages/filling/filling" @click="gotopage">
						<view class="logo">
							<image src="../../static/my/cz.png" mode="widthFix"></image>
						</view>
						<view class="unit" >{{Lang.lang('rechargeCoins')}}</view>
					</view>
					
					<view class="lump" data-url="/pages/mention/mention" @click="gotopage">
						<view class="logo">
							<image src="../../static/my/tx.png" mode="widthFix"></image>
						</view>
						<view class="unit" >{{Lang.lang('withdrawalofcoins')}}</view>
					</view>
					
					<view class="lump" data-url="/pages/trading/trading" @click="gotopage">
						<view class="logo">
							<image src="../../static/my/mx.png" mode="widthFix"></image>
						</view>
						<view class="unit" >{{Lang.lang('transaction')}}</view>
					</view>
				</view>
			</view>


		</view>

		<view class="footer">
			<view class="title">{{Lang.lang('page_title_text19')}}</view>
			<view class="friend_box">
				<block v-for="(item, index) in footer" :key="index">
					<view class="friend">
						<image :src='item.img' mode="heightFix"></image>
					</view>
				</block>
			</view>
		
			<view class="other_box">
				<block v-for="(item, index) in other" :key="index">
					<view class="other">
						<image :src='item.img' mode="heightFix"></image>
					</view>
				</block>
			</view>
		
			<view class="rule_box">
				<view class="rule">
					<view class="t01">{{Lang.lang('page_title_text20')}}</view>
					<view class="t02">Cex</view>
					<view class="t02">Dex</view>
					<view class="t02">{{Lang.lang('page_title_text21')}}</view>
					<view class="t02">{{Lang.lang('page_title_text22')}}</view>
					<view class="t02">NFT</view>
				</view>
				<view class="rule"></view>
				<view class="rule">
					<view class="t01">{{Lang.lang('page_title_text23')}}</view>
					<view class="t02">{{Lang.lang('page_title_text24')}}</view>
					<view class="t02">{{Lang.lang('page_title_text25')}}</view>
					<view class="t02">{{Lang.lang('page_title_text26')}}</view>
					<view class="t02">{{Lang.lang('page_title_text19')}}</view>
					
				</view>
			</view>
		
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				language:'zh',
				options2:{
					size:120,
					width:150,
					height:150
				},
				login_win:false,
				usdtBalance:'0.00',
				mask:false,
				loginId:'',
				inviteId:'',
				injected: false,
				injectTimes:0,
				address:'',
				myAddress:'',
				subAddress:'',
				shareUrl:'',
				isReg:false,
				lsdBalance:'0.0000',
				fuwenBalance:'0',
				urldata:'fsfsgdhfhfghfghfghgf',
				login: false,
				scroll: false,
				pupu: false,
				login: false,
				langIndex: '',
				langData: [{
						name: 'kr',
					},
					{
						name: 'en',
					},
					{
						name: 'tc',
					}
				],
				bscIndex: 1,
				bscData: [{
						name: 'BSC',
					},
					{
						name: 'BSC02',
					},
					{
						name: 'BSC03',
					}
				],

				bscText: 'BSC',
				navlist: [{
						img: '../../static/menus/menu01.png',
						name: '首頁',
						url: '/pages/index/index'
					},
					{
						img: '../../static/menus/menu02.png',
						name: '交易',
						url: '/pages/trading/trading'
					},
					{
						img: '../../static/menus/menu08.png',
						name: '閃兌',
						url: '/pages/flash/flash'
					},	
					{
						img: '../../static/menus/menu07.png',
						name: '团队',
						url: '/pages/team/team'
					},
					// {
					// 	img: '../../static/menus/menu03.png',
					// 	name: '充幣',
					// 	url: '/pages/filling/filling'
					// },
					{
						img: '../../static/menus/menu04.png',
						name: '提幣',
						url: '/pages/mention/mention'
					},
					{
						img: '../../static/menus/menu05.png',
						name: '資產',
						url: '/pages/assets/assets'
					}
				],
				footer: [{
						img: '../../static/footer/friend01.png'
					},
					{
						img: '../../static/footer/friend02.png'
					},
					{
						img: '../../static/footer/friend03.png'
					},
					{
						img: '../../static/footer/friend04.png'
					},
					{
						img: '../../static/footer/friend05.png'
					},
					{
						img: '../../static/footer/friend06.png'
					},
					{
						img: '../../static/footer/friend07.png'
					},
					{
						img: '../../static/footer/friend08.png'
					}
				],
				other: [{
						img: '../../static/footer/other01.png'
					},
					{
						img: '../../static/footer/other02.png'
					},
					{
						img: '../../static/footer/other03.png'
					},
					{
						img: '../../static/footer/other04.png'
					},
					{
						img: '../../static/footer/other05.png'
					},
					{
						img: '../../static/footer/other06.png'
					},
				],
				code:''

			};
		},
		mounted() {},
		onPullDownRefresh() {},
		onLoad(e) {
			let me = this;
			me.language = me.Lang.getLang();
			me.changeLanguage();
			if (!me.injected) me.linkWallet();
		},

		methods: {
			copyText(e){
				let me = this;
				uni.setClipboardData({
					data: e.currentTarget.dataset.txt,
					success: function () {
						uni.showToast({
							title:me.Lang.lang('copyOk'),
							icon:'none'
						})
					}
				});
			}, 
			changeLanguage(){
				let me=this;
				for(var i=0;i<me.navlist.length;i++){
					if(i==0){
						me.navlist[i].name = me.Lang.lang('home')
					}else if(i==1){
						me.navlist[i].name = me.Lang.lang('transaction')
					}else if(i==2){
						me.navlist[i].name = me.Lang.lang('flashExchange')
					}else if(i==3){
						me.navlist[i].name = me.Lang.lang('team')
					}else if(i==4){
						me.navlist[i].name = me.Lang.lang('withdrawalofcoins')
					}else if(i==5){
						me.navlist[i].name = me.Lang.lang('asset')
					}
				}
				
			},
			maskChange(_flag){
				this.mask = _flag;
			},
			share_url(){
				let me=this
				if(me.address){
					var url=me.He.getWapShareUrl(false,me.code);
				}
				return url
			},
			getLoginDate(){
				let me = this;
				let address = me.address;
				let url = window.location.href;
				if(url.indexOf("?u=") == -1){
					url = '';
				}else{
					if(url.indexOf("#") != -1){
						url = url.substring(0,url.indexOf("#"));
					}
					if(url.indexOf("&") != -1){
						url = url.substring(url.indexOf("?u=")+3,url.indexOf("&"));
					}else{
						url = url.substring(url.indexOf("?u=")+3,url.length);
					}
					
				}
				me.inviteId = url;
			},
			async linkWallet() {
				let me = this;
				if (me.injected) return false;
				if (!me.injected) {
					var account = await me.He.getAccount();
					var fireContract = await me.He.contractInit();
					if(account){
						me.address = account.address;
						
						let address=me.He.isLogin();
						me.myAddress = me.address;
						me.getLoginDate();
						if(me.He.getAddress() != me.address){
							me.login_win = true;
						}else{
							me.login_win = false;
							// me.getUsdtBalance();
							me.register();
						}
					}else {
						me.injectTimes++;
						if (me.injectTimes > 20) {
							console.log('钱包地址注入失败')
							return false;
						} else {
							console.log('钱包地址注入重试'+me.injectTimes)
							setTimeout(() => {
								me.linkWallet();
							}, 500)
						}
					}
			
				} else {
					me.injectTimes++;
					if (me.injectTimes > 20) {
						console.log('钱包地址注入失败')
						//非DAPP环境 无法操作 跳转到空白提示页
						
						return false;
					} else {
						console.log('钱包地址注入重试'+me.injectTimes)
						setTimeout(() => {
							me.linkWallet();
						}, 1000)
					}
				}
			},
			register() {
				let me = this;
				me.He._post(
					'/api/auth/register',
					{ address: me.myAddress, p_address: me.inviteId },
					true,
					res => {
						if (res.code == 200) {
							// this.He.Success(res.msg);
							me.He.login(res.data.access_token,me.address);
							
							
							if(me.He.isLogin() != false && me.He.getAddress() != false){
								me.subAddress = me.address.substring(0,5)+"....."+me.address.substring(38,me.address.length);
								me.addressInput = me.subAddress
							}
							
							me.login_win = false;
							
							me.injected = true;
							
							me.getUserInfo();
							// me.exchangeList();
							// me.nodeList();
							// me.shibhPriceList();
							// me.noticeList();
						} else {
							this.He.Fail(res.msg);
						}
					},
					true
				);
			},
			getUserInfo(){
				let me = this;
				me.He._post(
					'/api/service/userInfo',
					{},
					true,
					res => {
						if (res.code == 200) {
							var data = res.data;
							me.lsdBalance = data.lsd;
							me.fuwenBalance = data.fuwen_balance;
							me.code = data.code;
							me.shareUrl=me.share_url();
						} else {
							this.He.Fail(res.msg);
						}
					},
					true
				);
			},
			copyMoneyUrl() {
				let that = this
				uni.setClipboardData({
					data: that.urldata,
					success: function() {
						that.Msg.Success('复制成功');
					},
					fail: function(error) {
						that.Msg.Fail('复制失败');
					}
				});
			},
			choiceBsc: function(e) {
				let that = this;
				that.bscIndex = e.target.value;
				that.bscText = that.bscData[that.bscIndex].name;
				// uni.setStorageSync('_language', lang);
				// that.loadData();
			},
			choiceLang: function(e) {
				let that = this;
				that.langIndex = e.target.value;
				let lang = that.Lang.lang('langData')[that.langIndex].type;
				uni.setStorageSync('_language', lang);
				location.reload()
			},
			loadData() {
				let me = this;
				me.He._get('main', {}, true, res => {});
			},
			autoListPage() {
				let that = this;
				that.pupu = !that.pupu;
			},
			autoSignin() {
				let that = this;
				that.login = !that.login;
			},
			gotopage(e) {
				var that = this;
				let url = e.currentTarget.dataset.url;
				//console.log(url);
				uni.navigateTo({
					url: url
				});
			},
			backPage() {
				uni.navigateBack({});
			}
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 25) {
				this.scroll = true;
			} else if (Object.scrollTop < 25) {
				this.scroll = false;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content_box {
		width: 92%;
		margin: 0 auto;
		padding: 4vw 0;
		background: linear-gradient(to bottom, #292929, #1B1B1B);
	}

	.arrow {
		font-size: 6vw;
	}

	.main01 {
		width: 100%;
		margin: auto;
	}
	
	.main01  image{
		width: 100%;
	}
	.main01 .ceng {
		position: absolute;
		z-index: 9;
		width: 100%;
		display: flex;
		justify-content: space-between;
	}

	.main01 .ceng .zuob {
		width: 78%;
	}

	.main01 .ceng .balance {
		color: #fff;
		font-size: 3.5vw;
		margin: 5vw 3vw 3vw 3vw;
	}

	.main01 .ceng .money {
		color: #fff;
		font-size: 8vw;
		margin: 0vw 3vw;
		font-weight: bold;
	}

	.main01 .ceng .content {
		display: flex;
		margin-left: 3vw;
		width: 100%;
	}

	.main01 .ceng .content .piece .biao {
		display: flex;
	}

	.main01 .ceng .content .piece {
		width: 50%;
	}

	.main01 .ceng .content .piece .biao .line {
		background-color: #2ACB95;
		width: 3px;
		height: 4vw;
		margin: 2vw 2vw 0vw 0vw;
	}

	.main01 .ceng .content .piece .biao .text {
		color: #fff;
		font-size: 3vw;
		margin-top: 1.5vw;
	}

	.main01 .ceng .content .piece .qian {
		color: #fff;
		font-size: 4vw;
		font-weight: bold;
		margin-top: 1vw;
	}

	.main01 .ceng .youb {
		margin-right: 7vw;
		padding-top: 5vw;
	}

	.main01 .one {
		width: 16vw;
		margin-top: 1vw;
	}

	.main01 .one .word {
		position: absolute;
		color: #fff;
		font-size: 3.5vw;
		z-index: 99;
		padding: 1.5vw 0vw 0vw 5.5vw;
	}

	.main01 .one .word1 {
		position: absolute;
		color: #333;
		font-size: 3.5vw;
		z-index: 99;
		padding: 1.5vw 0vw 0vw 5.5vw;
	}

	.main02 {
		border: 1px solid #F4F2F2;
		border-radius: 3vw;
		width: 100%;
		margin: 3vw auto 0vw;
	}

	.main02 .kuai01 {
		border-radius: 3vw;
		padding-bottom: 3vw;
		display: flex;

	}

	.se01 {
		background-color: #F1F7FF;
	}

	.se02 {
		background-color: #EBEEFF;
	}

	.se03 {
		background-color: #FFF9E9;
	}

	.main02 .kuai01 .zuob {
		width: 100%;
	}

	.main02 .kuai01 .balance {
		color: #333;
		font-size: 3.5vw;
		padding: 5vw 3vw 3vw 3vw;
	}

	.main02 .kuai01 .money {
		color: #333;
		font-size: 8vw;
		margin: 0vw 3vw;
		font-weight: bold;
	}

	.main02 .kuai01 .content {
		display: flex;
		width: 100%;
		padding: 4vw 0;
	}

	.main02 .kuai01 .content .piece .biao {
		display: flex;
		flex: 1;
		justify-content: center;
	}

	.main02 .kuai01 .content .piece {
		width: 50%;
	}

	.main02 .kuai01 .content .piece .biao .line {
		background-color: #4C8EFE;
		width: 3px;
		height: 4vw;
		margin: 2vw 2vw 0vw 0vw;
	}

	.main02 .kuai01 .content .piece .biao .line01 {
		background-color: #F7B60C;
		width: 3px;
		height: 4vw;
		margin: 2vw 2vw 0vw 0vw;
	}

	.main02 .kuai01 .content .piece .biao .text {
		color: #4C8EFE;
		font-size: 3vw;
		margin-top: 1.5vw;
	}

	.main02 .kuai01 .content .piece .qian {
		color: #333;
		font-size: 4vw;
		font-weight: bold;
		margin-top: 1vw;
		text-align: center;
		padding-top: 2vw;
	}

	.main02 .kuai01 .youb {
		// width: 12%;
		position: absolute;
		right: 3vw;
	}

	.main02 .kuai01 .youb image {
		width: 240%;
	}

	.main02 .a-center {
		width: 100%;
		margin: auto;
		display: flex;
		justify-content: space-between;
		padding: 3vw 2vw;
	}

	.main02 .a-center .lump {
		display: flex;
		align-items: center;
		margin-left: 3vw;
	}
	
	.main02 .a-center .lump:nth-child(1){
		margin-left: 0;
	}

	.main02 .a-center .lump .logo {
		width: 5.5vw;
		height: 5.5vw;
	}

	.main02 .a-center .lump .logo image {
		width: 100%;
	}

	.main02 .a-center .lump .unit {
		color: #fff;
		font-size: 4vw;
		flex: 1;
		margin-left: 1vw;
		
	}

	.main02 .a-center .stripe {
		width: 1px;
		height: 6vw;
		background-color: #fff;
	}
	
	.mask{
		width: 100%;
		position: fixed;
		z-index: 99;
		top: 0;
		height: 100vh;
		left:0;
		background: rgba(0, 0, 0, 0.7);
		.m_box{
			width: 100%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 0 5% 3vh;
			.m_item{
				width: 100%;
				padding: 5vw 8vw 7vw;
				background: #ffffff;
				border-radius: 4vw;
				text-align: center;
				position: relative;
				.m_tit{
					font-size: 30rpx;
					font-weight: bold;
					width: 100%;
				}
				.m_qr_itme{
					width: 80%;
					margin: 6vw 10%;
					padding: 4vw 0;
					border: 1rpx solid #257BF9;
					border-radius: 20rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					.qr_code{
						width: 40vw;
						height: 40vw;
					}
				}
				.m_t1{
					width: 100%;
					font-size: 26rpx;
					color: #666666;
					font-weight: bold;
				}
				.m_t2{
					width: 100%;
					padding: 30rpx 0 50rpx;
					font-size: 26rpx;
					font-weight: bold;
					word-wrap: break-word;
				}
				.btn{
					width: 90%;
					margin-left: 5%;
					text-align: center;
					padding: 3vw 0;
					border-radius: 20rpx;
					background: #257BF9;
					color: #ffffff;
					font-size: 30rpx;
				}
				.close{
					position: absolute;
					right: 4vw;
					top: 4vw;
					font-size: 35rpx;
				}
				.input_box{
					width: 100%;
					padding: 50rpx 0;
					.input_item{
						width: 100%;
						margin-top: 20rpx;
						.i_txt{
							width: 100%;
							text-align: left;
							font-size: 26rpx;
							padding-bottom: 10rpx;
							color: #333333;
						}
						.i_box{
							height: 12vw;
							width: 100%;
							padding: 0 15rpx;
							font-size: 28rpx;
							color: #333333;
							background: #f9f9f9;
							border-radius: 15rpx;
						}
					}
				}
			}
		}
	}
	.menu001{
		width: 90%;
		margin-left: 5%;
		text-align: center;
		padding: 3vw 0;
		border-radius: 20rpx;
		background: #257BF9;
		color: #ffffff;
		font-size: 30rpx;
	}
</style>